//
//  RCMemberInfoDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-6-18.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMemberInfoDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"


@implementation RCMemberDetailInfo

@synthesize title = _title;
@synthesize content = _content;

-(id)init{
    self = [super init];
    if (nil == self) {
        return nil;
    }
    self.title = nil;
    self.content = nil;
    return self;
}

-(void)dealloc{
    self.title = nil;
    self.content = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCMemberDetailInfo *retObject = nil;
    retObject = [[RCMemberDetailInfo alloc]init];
    if (nil == retObject) {
        return nil;
    }
    NSString *title = [data stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeTrim];
    NSString *desc = [data stringValueForKey:@"desc" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.title = title;
    retObject.content = desc;
    return [retObject autorelease];
}

@end

@implementation RCMemberInfoDataModel

@synthesize detailInfoArray = _detailInfoArray;

-(id)init{
    self = [super init];
    if (nil == self) {
        return nil;
    }
    self.detailInfoArray = nil;
    return self;
}

-(void)dealloc{
    self.detailInfoArray = nil;
    [super dealloc];
}

+(void)buildSimulationData:(RCMemberInfoDataModel *)memberDataModel{
    NSMutableArray *dataArray = [[NSMutableArray alloc]initWithCapacity:1];
    RCMemberDetailInfo *detailInfo1 = [[RCMemberDetailInfo alloc]init];
    detailInfo1.title = @"如意行会员卡";
    detailInfo1.content = @"如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍如意行会员卡介绍";
    [dataArray addObject:detailInfo1];
    [detailInfo1 release];
    
    RCMemberDetailInfo *detailInfo2 = [[RCMemberDetailInfo alloc]init];
    detailInfo2.title = @"如意行会员卡实用须知";
    detailInfo2.content = @"如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知如意行会员卡实用须知";
    [dataArray addObject:detailInfo2];
    [detailInfo2 release];
    
    RCMemberDetailInfo *detailInfo3 = [[RCMemberDetailInfo alloc]init];
    detailInfo3.title = @"如意行会员卡办理流程";
    detailInfo3.content = @"如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程如意行会员卡办理流程";
    [dataArray addObject:detailInfo3];
    [detailInfo3 release];
    memberDataModel.detailInfoArray = [NSArray arrayWithArray:dataArray];
    [dataArray release];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCMemberInfoDataModel *retObject = nil;
    retObject = [[RCMemberInfoDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
#ifdef USE_SIMULATION_DATA
    // 构造模拟数据
    [self buildSimulationData:retObject];
    return [retObject autorelease];
#endif
    
    NSDictionary *dict = [data dictionaryValueForKey:@"data" defaultValue:nil];
    if (nil == dict) {
        return [retObject autorelease];
    }
    NSArray *infoList = [dict arrayValueForKey:@"list" defaultValue:nil];
    if (infoList != nil && [infoList count] > 0) {
        NSMutableArray *infoTempArray = [[NSMutableArray alloc]initWithCapacity:1];
        for (int i=0; i < [infoList count]; i++) {
            NSDictionary *detailDict = [infoList safeObjectAtIndex:i];
            if (nil == detailDict) {
                continue;
            }
            RCMemberDetailInfo *detailInfo = [RCMemberDetailInfo parseDataFromJSON:detailDict];
            [infoTempArray addObject:detailInfo];
        }
        retObject.detailInfoArray = [NSArray arrayWithArray:infoTempArray];
        [infoTempArray release];
    }
    return [retObject autorelease];

}

@end
